package com.qf.fmall2202.utils;

import cn.hutool.http.HttpUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class HttpTest {

    public static void main(String[] args) throws IOException {
        //1.通过Java代码访问百度
//        System.out.println(HttpUtil.get("www.baidu.com"));
        String urlStr = "http://www.baidu.com";
        URL url = new URL(urlStr);


        //建立到url连接
        URLConnection urlConnection = url.openConnection();//注意:这里并没有发送请求，只是创建对象

        urlConnection.connect(); //真正发送tcp请求

        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

        String line = null;

        while ((line=bufferedReader.readLine())!=null){
            System.out.println(line);

        }
        bufferedReader.close();
        inputStream.close();
    }

}
